package com.yufubao.api.controller.management.system;

import com.yufubao.framework.annotation.SystemLog;
import com.yufubao.framework.result.ResponseResult;
import com.yufubao.model.dto.management.sys.SaveMenuDto;
import com.yufubao.model.dto.management.sys.UpdateMenuDto;
import com.yufubao.service.service.management.authorization.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2024/9/12 16:38
 */
@Api("菜单管理")
@RestController
@RequestMapping("/applet/management/sys/menu")
public class SysMenuController {


    @Autowired
    private MenuService menuService;

    /**
     * @description 查询菜单父子列表
     * @param status
     * @param menuName
     * @return com.zhangzhan.domain.commcon.ResponseResult
     */
    @RequestMapping(value = "/menuParentChildList",method = RequestMethod.GET)
    @ApiOperation(value = "查询菜单父子列表")
    @SystemLog(info = "查询菜单父子列表")
    public ResponseResult menuParentChildList(@RequestParam(value = "status",required = false)  String status,
                                              @RequestParam(value = "menuName",required = false) String menuName){
        return menuService.menuParentChildList(status, menuName);
    }


    /**
     * @description 新增菜单
     *
     * @return com.zhangzhan.domain.commcon.ResponseResult
     */
    @RequestMapping(value = "/saveMenu",method = RequestMethod.POST)
    @ApiOperation(value = "新增菜单")
    @SystemLog(info = "新增菜单")
    public ResponseResult saveMenu(@RequestBody @Validated SaveMenuDto saveMenuDto){
        return menuService.saveMenu(saveMenuDto);
    }


    /**
     * @description 菜单修改前回显/根据id查询
     *
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 13:44
     */
    @RequestMapping(value = "/echoInfo/{id}",method = RequestMethod.GET)
    @ApiOperation(value = "菜单修改前回显")
    @SystemLog(info = "菜单修改前回显")
    public ResponseResult rowBackMenu(@PathVariable("id") Long id){
        return menuService.rowBackMenu(id);
    }

    /**
     * @description 修改菜单
     * @param updateMenuDto
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 14:11
     */
    @RequestMapping(value = "/updateMenu",method = RequestMethod.PUT)
    @ApiOperation(value = "修改菜单")
    @SystemLog(info = "修改菜单")
    public ResponseResult updateMenu(@RequestBody @Validated UpdateMenuDto updateMenuDto){
        return menuService.updateMenu(updateMenuDto);
    }

    /**
     * @description 删除菜单
     * @param menuId
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 14:14
     */
    @RequestMapping(value = "/deleteMenuById/{menuId}",method = RequestMethod.DELETE)
    @ApiOperation(value = "删除菜单")
    @SystemLog(info = "删除菜单")
    public ResponseResult deleteMenuById(@PathVariable("menuId") Long menuId){
        return menuService.deleteMenuById(menuId);
    }

    /**
     * @description 获取菜单树接口
     *
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 15:20
     */
    @RequestMapping(value = "/treeselect",method = RequestMethod.GET)
    @ApiOperation(value = "获取菜单树接口")
    @SystemLog(info = "获取菜单树接口")
    public ResponseResult treeselect(){
        return  menuService.treeselect();
    }



}
